package org.six.background.controller;

import com.alipay.api.domain.Account;
import org.six.background.mapper.InshopMapper;
import org.six.background.mapper.ShopMapper;
import org.six.background.mapper.ShoptypeMapper;
import org.six.background.mapper.UserMapper;
import org.six.background.pojo.*;
import org.six.background.service.AccountService;
import org.six.background.service.InshopService;
import org.six.background.service.ShopService;
import org.six.background.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@ResponseBody
@RequestMapping("/inshop")
public class InshopController {
    @Autowired
    private InshopService inshopService;

    @Autowired(required = false)
    private UserMapper userMapper;
    @Autowired(required = false)
    private ShopMapper shopMapper;
    @RequestMapping("/show")
    public List<Inshop> inshops(){
        return inshopService.inshopshow();
    }
    @RequestMapping("/add")
    public String inshopAdd(String usname,int inidcard,int usphone,String shopname,int innum){
        System.out.println("out");
        System.out.println(usname);
        System.out.println(inidcard);
        System.out.println(usphone);
        System.out.println(shopname);
        System.out.println(innum);
        return inshopService.inshopAdd(usname,inidcard,usphone,shopname,innum);
    }
    @RequestMapping("/list")
    public Map selectlist(){
        //1单独查出全部的用户信息
        //2单独查出全部的商品信息
        //3把他们封成map返回
        Map map=new HashMap();
        List<User> users=userMapper.selectByExample(null);
        List<Shop> shops=shopMapper.selectByExample(null);
        map.put("users",users);
        map.put("shops",shops);
        System.out.println(map.toString());
        return map;
    }
    @RequestMapping("/inchart")
    public Map inchart(){
        return inshopService.inchart();

    }
    @RequestMapping("/user")
    public List selectlist(Integer usid){
        UserExample userExample=new UserExample();
        UserExample.Criteria uc=userExample.createCriteria();
        uc.andUsidEqualTo(usid);
        List<User> users = userMapper.selectByExample(userExample);
        System.out.println("用户信息："+users);
        return users;
    }
    @RequestMapping("/accountAll")
    public Map inshopAll(int page,int pagesize){
        Map map = inshopService.inshopAll(page, pagesize);
        return map;
    }
}
